<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>记事本</title>
		<link rel="stylesheet" type="text/css" href="css/index.css"/>
		<script src="vue.js" type="text/javascript"></script>
	</head>
	<body>
		<selection id="todoapp" >
			<!-- 输入框 -->
			<header class="header">
				<h1>我的记事本</h1>
				<input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务" 
				class="new-todo"/>
			</header>
			<!-- 列表区域 -->
			<selection class="main">
				<ul class="todo-list">
					<li class="todo" v-for="(item,index) in list">
						<div class="view">
							<span class="index">{{ index+1 }}.</span>
							<label>{{ item }}</label>
							<button class="destroy" @click="remove(index)"></button>
						</div>
					</li>
				</ul>
			</selection>
			<!-- 统计和清空 -->
			<footer class="footer" ><!-- 父元素使用v-show="list.length!=0"将会隐藏所有后代内容 -->
				<span class="todo-count" v-if="list.length!=0"><strong>记事本还剩{{ list.length }}件事</strong></span>
				<button class="clear-completed" @click="clear" v-if="list.length!=0">清空记事本</button>
			</footer>
		</selection>
		<!-- 底部 -->
		<footer class="info">
			
		</footer>
		<script>
			var app=new Vue({
				el:"#todoapp",
				data:{
					list:["打篮球","踢足球","打羽毛球","打乒乓球"],
					inputValue:""
				},
				methods: {
					//添加功能
					add:function() {
						this.list.push(this.inputValue);
					},
					//删除功能
					remove:function(index){
						//console.log("删除")
						this.list.splice(index,1)
					},
					clear:function(){
						this.list=[];
					}
				},
			})
		</script>
	</body>
</html>
